from typing import List


class Solution:
    def pourWater(self, heights: List[int], v: int, k: int) -> List[int]:
        for _ in range(v):
            left = k
            for i in range(k - 1, -1, -1):
                if heights[i] < heights[i + 1]:
                    left = i
                elif heights[i] > heights[i + 1]:
                    break
            if left < k:
                heights[left] += 1
                continue

            right = k
            for i in range(k + 1, len(heights)):
                if heights[i] < heights[i - 1]:
                    right = i
                elif heights[i] > heights[i - 1]:
                    break
            if right > k:
                heights[right] += 1
                continue

            heights[k] += 1

        return heights


if __name__ == "__main__":
    # [2,2,2,3,2,2,2]
    print(Solution().pourWater(heights=[2, 1, 1, 2, 1, 2, 2], v=4, k=3))

    # [2,3,3,4]
    print(Solution().pourWater(heights=[1, 2, 3, 4], v=2, k=2))

    # [4,4,4]
    print(Solution().pourWater(heights=[3, 1, 3], v=5, k=1))
